package nico.styTool.click

import android.widget.ImageView
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.LinearLayoutManager
import cc.shinichi.library.ImagePreview
import com.blankj.utilcode.util.RegexUtils
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.drake.net.Get
import com.drake.net.NetConfig
import com.drake.net.utils.scopeDialog
import com.example.blade.InputBox
import com.example.blade.InputBox.Companion.SaveData
import kotlinx.android.synthetic.main.layout_custom_tools.view.*
import nico.styTool.R
import java.util.*


class DeveloperTools(requireActivity: FragmentActivity) {

    init {
        /*InputBox.Builder(requireActivity, Hint = arrayOf("请输入网址") )
            .setPositiveButton {
                val str = SaveData
                NetConfig.host = str
                requireActivity.scopeDialog {
                    val request = Get<String>(NetConfig.host).await()
                    MessageDialog.show(BaseBox, null, "点击看图(保存)", "知道了")
                        .setCustomView(R.layout.layout_custom_tools) { _, v ->
                            val items: MutableList<String> = ArrayList()
                            RegexUtils.getMatches(pattern, str)
                            v.recyclerView3.also {
                                it.layoutManager = LinearLayoutManager(requireActivity)
                                val layoutRes = android.R.layout.activity_list_item
                                val adapter = object :
                                    BaseQuickAdapter<String, BaseViewHolder>(layoutRes, items) {
                                    override fun convert(holder: BaseViewHolder, item: String) {
                                        holder.apply {
                                            setText(android.R.id.text1, item)
                                            getView<ImageView>(android.R.id.icon).apply {
                                                Glide.with(context).load(item).into(this)
                                            }
                                        }
                                    }
                                }
                                it.adapter = adapter.apply {
                                    setOnItemClickListener { _, _, _ ->
                                        ImagePreview
                                            .getInstance()
                                            .setContext(requireActivity)
                                            .setIndex(0)
                                            .setImageList(items)
                                            .start()
                                    }
                                }
                            }

                        }

                }
            }.create()*/

    }

    companion object {
        private const val pattern = "http[s:]{1,2}//[^\\s'\"<>]*?.png"
    }
}